import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class demo7 {
    private final Person;
    Class clz=Class.forName("Person");

    public demo7() throws ClassNotFoundException {
        try {
            Method getAge=clz.getDeclaredMethod("getAge",null);
            getAge.setAccessible(true);

            Object returnAge=getAge.invoke(null,null);
            System.out.println("年龄是:"+returnAge);
            Method silentMethod=clz.getDeclaredMethod("silentMethod",null);
            silentMethod.setAccessible(true);

            Method setName=clz.getDeclaredMethod("setName",String.class);
            setName.invoke(Person,"New Person");

            Object returName=clz.getDeclaredMethod("getName").invoke(Person);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
